| Conditions | 4 |
| Paths | 9 |
| Total Lines | 158 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import { |
||
| 29 | return (dispatch) => { |
||
| 30 | |||
| 31 | dispatch(dismissEditor({ stateKey })); |
||
| 32 | |||
| 33 | dispatch( |
||
| 34 | setLoaderState({state: true, stateKey }) |
||
| 35 | ); |
||
| 36 | |||
| 37 | if (typeof dataSource === 'function') { |
||
| 38 | |||
| 39 | // passing extraParams.parentId |
||
| 40 | // to custom func so they can do partial |
||
| 41 | // loading |
||
| 42 | dataSource(extraParams).then((response) => { |
||
| 43 | |||
| 44 | if (response && response.data) { |
||
| 45 | |||
| 46 | dispatch( |
||
| 47 | setLoaderState({ state: false, stateKey }) |
||
| 48 | ); |
||
| 49 | |||
| 50 | if (type !== 'tree') { |
||
| 51 | |||
| 52 | dispatch({ |
||
| 53 | type: SET_DATA, |
||
| 54 | data: response.data, |
||
| 55 | total: response.total, |
||
| 56 | currentRecords: response.data, |
||
| 57 | success: true, |
||
| 58 | stateKey, |
||
| 59 | editMode: extraParams.editMode |
||
| 60 | }); |
||
| 61 | } |
||
| 62 | |||
| 63 | else { |
||
| 64 | // upon the return of read |
||
| 65 | // response needs to clarify |
||
| 66 | // whether this is a partial update |
||
| 67 | dispatch(setTreeData({ |
||
| 68 | data: response.data, |
||
| 69 | stateKey, |
||
| 70 | showTreeRootNode, |
||
| 71 | parentId: extraParams.parentId, |
||
| 72 | partial: response.partial, |
||
| 73 | editMode: extraParams.editMode, |
||
| 74 | total: response.total |
||
| 75 | })); |
||
| 76 | } |
||
| 77 | |||
| 78 | return; |
||
| 79 | } |
||
| 80 | |||
| 81 | if (response && !response.data) { |
||
| 82 | /* eslint-disable no-console */ |
||
| 83 | console.warn( |
||
| 84 | `A response was recieved |
||
| 85 | but no data entry was found` |
||
| 86 | ); |
||
| 87 | console.warn( |
||
| 88 | `Please see |
||
| 89 | https://github.com/bencripps/react-redux-grid |
||
| 90 | for documentation` |
||
| 91 | ); |
||
| 92 | /* eslint-enable no-console */ |
||
| 93 | } |
||
| 94 | |||
| 95 | dispatch( |
||
| 96 | setLoaderState({ state: false, stateKey }) |
||
| 97 | ); |
||
| 98 | |||
| 99 | dispatch({ |
||
| 100 | type: ERROR_OCCURRED, |
||
| 101 | error: 'Unable to Retrieve Grid Data', |
||
| 102 | errorOccurred: true, |
||
| 103 | stateKey |
||
| 104 | }); |
||
| 105 | |||
| 106 | }); |
||
|
|
|||
| 107 | } |
||
| 108 | |||
| 109 | else if (typeof dataSource === 'string') { |
||
| 110 | |||
| 111 | if (type !== 'tree') { |
||
| 112 | |||
| 113 | return Api({ |
||
| 114 | route: dataSource, |
||
| 115 | method: 'GET' |
||
| 116 | }).then((response) => { |
||
| 117 | |||
| 118 | if (response && response.data) { |
||
| 119 | |||
| 120 | dispatch({ |
||
| 121 | type: SET_DATA, |
||
| 122 | data: response.data, |
||
| 123 | total: response.total, |
||
| 124 | currentRecords: response.data, |
||
| 125 | success: true, |
||
| 126 | stateKey, |
||
| 127 | editMode: extraParams.editMode |
||
| 128 | }); |
||
| 129 | |||
| 130 | } |
||
| 131 | |||
| 132 | else { |
||
| 133 | dispatch({ |
||
| 134 | type: ERROR_OCCURRED, |
||
| 135 | error: 'Unable to Retrieve Grid Data', |
||
| 136 | errorOccurred: true, |
||
| 137 | stateKey |
||
| 138 | }); |
||
| 139 | } |
||
| 140 | |||
| 141 | dispatch( |
||
| 142 | setLoaderState({state: false, stateKey }) |
||
| 143 | ); |
||
| 144 | }); |
||
| 145 | |||
| 146 | } |
||
| 147 | |||
| 148 | return Api({ |
||
| 149 | route: dataSource, |
||
| 150 | method: 'GET', |
||
| 151 | queryStringParams: { |
||
| 152 | parentId: extraParams.parentId |
||
| 153 | } |
||
| 154 | }).then((response) => { |
||
| 155 | |||
| 156 | if (response && response.data) { |
||
| 157 | |||
| 158 | // response needs to specify |
||
| 159 | // whether this is full or partial update |
||
| 160 | dispatch(setTreeData({ |
||
| 161 | data: response.data, |
||
| 162 | stateKey, |
||
| 163 | showTreeRootNode, |
||
| 164 | partial: response.partial, |
||
| 165 | parentId: extraParams.parentId |
||
| 166 | })); |
||
| 167 | |||
| 168 | } |
||
| 169 | |||
| 170 | else { |
||
| 171 | dispatch({ |
||
| 172 | type: ERROR_OCCURRED, |
||
| 173 | error: 'Unable to Retrieve Grid Data', |
||
| 174 | errorOccurred: true, |
||
| 175 | stateKey |
||
| 176 | }); |
||
| 177 | } |
||
| 178 | |||
| 179 | dispatch( |
||
| 180 | setLoaderState({state: false, stateKey }) |
||
| 181 | ); |
||
| 182 | }); |
||
| 183 | |||
| 184 | } |
||
| 185 | |||
| 186 | }; |
||
| 187 | }; |
||
| 445 |